export function gradient(color1:string, color2:string, steps:number) {
  const colors = [];
  // 将颜色转为RGB格式
  const rgb1=HexToRGB(color1);
  const rgb2=HexToRGB(color2);

  // 计算样条控制点
  let count = steps + 1;
  for (let i = 0; i < count; i++) {
    let t = i / steps;
    let r = rgb1.r + (rgb2.r - rgb1.r) * t;
    let g = rgb1.g + (rgb2.g - rgb1.g) * t;
    let b = rgb1.b + (rgb2.b - rgb1.g) * t;
    colors.push(RGBtoHex(r, g, b));
  }
  return colors;
}

// RGB颜色格式转换为Hex格式
export function RGBtoHex(r:number, g:number, b:number) {
  return (r << 16 | g << 8 | b).toString(16);
}

// Hex颜色格式转换为RGB格式
export function HexToRGB(hexColor:string) {
  let r = parseInt(hexColor.substring(0, 2), 16);
  let g = parseInt(hexColor.substring(2, 4), 16);
  let b = parseInt(hexColor.substring(4, 6), 16);
  return {r: r, g: g, b: b};
}